package com.jayden.scalevideoplayer.videoplayer;

import android.view.View;


public abstract class VideoControl implements VideoPlayerView.OnVideoPlayerViewListener {

    protected VideoPlayerView mVideoPlayerView;
    private OnFrameAvailableListener mFrameAvailableListener;

    public VideoControl(VideoPlayerView view) {
        this.mVideoPlayerView = view;
        initPlayer();
        if (mVideoPlayerView != null) {
            mVideoPlayerView.setVideoPlayerViewListener(this);
        }
    }

    /**
     * 设置视频开始绘制时的回调
     */
    public void setOnFrameAvailableListener(OnFrameAvailableListener listener) {
        this.mFrameAvailableListener = listener;
    }

    @Override
    public void onSurfaceTextureUpdated() {
        if (mFrameAvailableListener != null) {
            mFrameAvailableListener.onFrameAvailable();
            mVideoPlayerView.setPlaceholderVisibility(View.GONE);
            mFrameAvailableListener = null;
        }
    }

    public abstract void initPlayer();

    public interface OnFrameAvailableListener {
        void onFrameAvailable();
    }
}
